﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using AspnetCore_3_1Demo.Models;
using Dal;
using System.Data.Common;
using System.Data;
using Newtonsoft.Json;
using Dal.MsSqlDBOne;
using Common;
using Model;
using Dapper;
using Dal.IServices;

namespace AspnetCore_3_1Demo.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        private readonly IDbFactory _iDbFactory;

        public HomeController(ILogger<HomeController> logger, IDbFactory iDbFactory)
        {
            _logger = logger;
            this._iDbFactory = iDbFactory;
        }

        public IActionResult Index()
        {
            //using (IDbConnection conn = _iDbFactory.Create())
            //{
            //    var data = conn.Query("select * from Sys_Role");
            //    return Content(JsonConvert.SerializeObject(data));
            //}

            //using (IDbConnection conn = _iDbFactory.GetDb<Dal.MsSqlDBOne.UserModel>())
            //{
            //    var data = conn.Query("select * from Sys_Role");
            //    return Content(JsonConvert.SerializeObject(data));
            //};


            //LoggerHelper.Info(name);

            RedisMQ.Produce(new RedisQueue<Student>() { Keyword = "AddStudent", Message = new Student() { ID = 1, Name = "三歪" } });
            return Content("成功");

            //return View();

        }

        public IActionResult Privacy()
        {
            return View();
        }

        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
